##########################################
#	BIAS WILL FIND A WAY	
#	AUTHOR: MARTIN BISGAARD	
#	DATE: 07-03-2015
#	
#	This script will extract 
#	the variables used from the 
#	original data sets	
#
#	The original data files can be 
#	downloaded at: http://http://bes2009-10.org/



dat<-read.dta("C:/mydirectory/CMSDATA.dta",convert.factors=FALSE)

##############################################
# EXTRACTING VARIABLES FROM THE CMS DATA SET #

newdat<-data.frame(
	"natretro"=dat$q18,
	"rpecon"=dat$q28,
	"rpbrown"=dat$q233_1,
	"rpbush"=dat$q233_2,
	"rpgov"=dat$q233_3,
	"rpeu"=dat$q233_4,
	"rpusgov"=dat$q233_5,
	"rpukbanks"=dat$q233_6,
	"rpusbanks"=dat$q233_7,
	"rppmort"=dat$q233_8,
	"rpoilco"=dat$q233_9,
	"rpintlfinance"=dat$q233_10,
	"rpother"=dat$q233_11,
	"rpnone"=dat$q233_12,
	"econprob"=dat$q96,

	"party.id"=dat$q32tot,
	"yrmon"=dat$yrmon,
	"date"=as.factor(as.numeric(as.factor(dat$yrmon))),
	"vote2"=dat$q6,
	"primesat"=dat$q5,
	"readnwsp"=dat$q106,

#controls
	"coneu"=dat$q29,
	"party.str"=dat$q34,
	"mortgage"=dat$q109,
	"education"=dat$q112,
	"income"=dat$q121,
	"gender"=dat$q2,
	"age"=dat$q3,
	"polatt"=dat$q35,
	"unemp"=dat$q114
	)

newdat<-newdat[newdat$date%in%1:71,]#focus attention on pre-2010 election dynamics
#save(newdat,file="newdat.RData")



####################################################
# VARIABLES USED FROM THE 2005-09 BES PANEL SURVEY #



dat<-read.dta("C:/mydirectory/BESpanel.dta",convert.factors=FALSE)

paneldat.wide<-data.frame(
	"pid.1"=dat$pre_q29,
	"econ.1"=dat$pre_q92,
	"date.1"=dat$pre_resp,

	"pid.2"=dat$cam_q18,
	"econ.2"=dat$cam_q55,
	"date.2"=dat$cam_resp,

	"pid.3"=dat$post_q13,
	"econ.3"=dat$post_q41,
	"date.3"=dat$post_res,
				
	"pid.4"=dat$oyo_q57,
	"econ.4"=dat$oyo_q73,
	"date.4"=dat$oyo_resp,
	
	"pid.5"=dat$y08_q27,
	"econ.5"=dat$y08_q48,
	"date.5"=dat$y08_date,			
	
	"pid.6"=dat$y09_q15,
	"econ.6"=dat$y09_q32,
	"date.6"=dat$y09_date,		
	
	#note wave 7 is where the responsibility items are (aaq100)
	"pid.7"=dat$aaq28,
	"econ.7"=dat$aaq87,
	"date.7"=dat$aapreres,	
	
	"pid.8"=dat$bbq18,
	"econ.8"=dat$bbq54,
	"date.8"=dat$bbcamres,

	"pid.9"=dat$ccq28,
	"econ.9"=dat$ccq87,
	"date.9"=dat$ccps_res,


	"resp.1"=dat$pre_q98,
	"resp.7"=dat$aaq93,
	
	"labtemp"=dat$pre_q84,
	"polattention"=dat$pre_q141,
	"pecon"=dat$pre_q91,
	"pecon.pro"=dat$pre_q93,
	"econ.pro"=dat$pre_q94,
	"pid.strength"=dat$pre_q33,
	"trustlab"=dat$pre_q81,
	"region"=dat$pre_q1,
	"age"=dat$pre_q148,
	"home"=dat$pre_q150,
	"mortgage"=dat$pre_q151,
	"education"=dat$pre_q155,
	"income"=dat$pre_q163,
	"work.type"=dat$pre_q168,	
	"unemp"=dat$pre_q169,
	"gender"=dat$pre_q180,		
	"brownrp"=dat$aaq100_1, #note that these Q are also in the prior wave
	"govrp"=dat$aaq100_4,
	"id"=dat$besid
	)

#save(paneldat.wide,file="paneldat.wide.RData")



